package com.atguigu.cloud.exp;

import com.atguigu.cloud.resp.ResultData;
import com.atguigu.cloud.resp.ReturnCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * ClassName:GlobalExceptionHandler
 * Package:com.atguigu.cloud.exp
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/6/19 - 16:07
 * @Version:v1.0
 */
@Slf4j
//@RestControllerAdvice //开启全局异常捕捉
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ResultData<String> exception(Exception e){
        System.out.println("#######come in GlobalExceptionHandler");
        log.error("全局异常信息:{}",e.getMessage(),e);
        return ResultData.fail(ReturnCodeEnum.RC500.getCode(),e.getMessage());
    }

}
